package leetcode;

import datastructure.binarytree.SingleListNode;

/**
 * Created by hao on 17-3-31.
 */
public class AddTwoNums {
  public static SingleListNode addTwoNumbers(SingleListNode l1, SingleListNode l2) {
    SingleListNode first = new SingleListNode(l1.val + l2.val);
//    ListNode first = null;
    while (l1.next != null || l2.next != null){
      SingleListNode node = first.next =new SingleListNode(l1.next.val + l2.next.val);
      first = node;
      l1 = l1.next;
      l2 = l2.next;
    }
      return first;
  }

  public static void main(String[] args) {
    SingleListNode l1First = new SingleListNode(2);
    SingleListNode l1Second = l1First.next = new SingleListNode(4);
    SingleListNode l1Third = l1Second.next = new SingleListNode(6);

    SingleListNode l2First = new SingleListNode(1);
    SingleListNode l2Second = l2First.next = new SingleListNode(2);
    SingleListNode l2Third = l2Second.next = new SingleListNode(3);
////    System.out.println(first);

    SingleListNode first = addTwoNumbers(l1First, l2First);
    while (first != null){
      System.out.println(first.val);
      first = first.next;
    }


  }
}
